<html>
<head><meta charset="utf-8"><title>Vector-Optimized Library of Kernels · project-portable-simd · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/index.html">project-portable-simd</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Vector-Optimized.20Library.20of.20Kernels.html">Vector-Optimized Library of Kernels</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="225633070"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Vector-Optimized%20Library%20of%20Kernels/near/225633070" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kris <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Vector-Optimized.20Library.20of.20Kernels.html#225633070">(Feb 09 2021 at 01:08)</a>:</h4>
<p>Howdy folks. I'm new to Rust, SIMD, and Zulip.  I'm working on a project with a Software Defined Radio (SDR) and one of my goals is migrate as much as I can to Rust. A library that our old code uses is called VOLK (Vector-Optimized Library of Kernels).  It can be found at <a href="https://github.com/gnuradio/volk">https://github.com/gnuradio/volk</a>.  This library does a lot of useful things for SDRs using SIMD.  I'm very interested in seeing what I can do to get a few of the functions that I use working in RUST or just straight up replace them with something better. As such 'portable-simd' is very intriguing. I'm looking for advice and suggestions on my path forward. Is there anyone here who might be able to help?  I am game for contributing some if that suits my solution. </p>
<p>Here is an example of some functions I'm looking to port over to RUST:  <a href="https://github.com/gnuradio/volk/blob/master/kernels/volk/volk_16i_s32f_convert_32f.h">https://github.com/gnuradio/volk/blob/master/kernels/volk/volk_16i_s32f_convert_32f.h</a> </p>
<p>Thoughts?</p>



<a name="225633932"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Vector-Optimized%20Library%20of%20Kernels/near/225633932" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Vector-Optimized.20Library.20of.20Kernels.html#225633932">(Feb 09 2021 at 01:19)</a>:</h4>
<p>So <code>core::simd</code> is not even in nightly at the moment (still working on fixing that). For the very first "what do I do?" I will offer you my common recommendation to "I would like to start doing SIMD, now, without worrying about compatibility concerns very much" of "consider the <code>wide</code> crate, by one of our co-leads, Lokathor." <a href="https://crates.io/crates/wide">https://crates.io/crates/wide</a> or one of its reverse-dependencies that transforms that into higher-order math, like <a href="https://crates.io/crates/ultraviolet">https://crates.io/crates/ultraviolet</a> (though that is aimed at graphics).</p>
<p>This is a personal and opinionated recommendation, to be clear, not an Official Rust Project one or anything like that. But I suggest it because it is easily pulled off <a href="http://crates.io">crates.io</a> and has a simple API similar to what we are trying to match in complexity (that is, ideally mostly not), and builds on stable, though it does not fully accelerate for all targets (mostly Intel ones atm, because it uses <code>core::arch</code>'s API surface).</p>



<a name="225634476"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Vector-Optimized%20Library%20of%20Kernels/near/225634476" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kris <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Vector-Optimized.20Library.20of.20Kernels.html#225634476">(Feb 09 2021 at 01:27)</a>:</h4>
<p>Thanks much for the advice.  Is there a way to see what my Rust code compiles down into to confirm what LLVM generated? I'll look over "wide" to see how I can apply it.</p>



<a name="225634573"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Vector-Optimized%20Library%20of%20Kernels/near/225634573" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Vector-Optimized.20Library.20of.20Kernels.html#225634573">(Feb 09 2021 at 01:29)</a>:</h4>
<p>I should also note that our API does not address:<br>
1) doing runtime detection of CPU features<br>
2) multiversioning code in a single binary<br>
you still have to use <code>target_feature</code> correctly and all that.<br>
and: the usual?<br>
disassemblers, Godbolt, etc.<br>
<code>rustc --help</code> gives several options for <code>rustc --emit</code></p>



<a name="225634697"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Vector-Optimized%20Library%20of%20Kernels/near/225634697" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Vector-Optimized.20Library.20of.20Kernels.html#225634697">(Feb 09 2021 at 01:31)</a>:</h4>
<p>With Cargo, you can examine the <code>target</code> directory or use <code>cargo rustc</code> as a command.</p>



<a name="225635206"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Vector-Optimized%20Library%20of%20Kernels/near/225635206" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Miguel Raz Guzmán Macedo <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Vector-Optimized.20Library.20of.20Kernels.html#225635206">(Feb 09 2021 at 01:38)</a>:</h4>
<p>Tangent for <span class="user-mention" data-user-id="281757">@Jubilee</span> - do people just memorize those arch tables to know what <code>_mm256_vfpt_whatever</code> needs and does or how do people even come close to being proficient at this?</p>



<a name="225635311"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Vector-Optimized%20Library%20of%20Kernels/near/225635311" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Vector-Optimized.20Library.20of.20Kernels.html#225635311">(Feb 09 2021 at 01:39)</a>:</h4>
<p>I presume they used the same solutions that Sherlock Holmes did for observing, memorizing, and thinking about all the details that he did. :^)</p>



<a name="225635369"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Vector-Optimized%20Library%20of%20Kernels/near/225635369" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Miguel Raz Guzmán Macedo <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Vector-Optimized.20Library.20of.20Kernels.html#225635369">(Feb 09 2021 at 01:40)</a>:</h4>
<p>...the power of deduction?</p>



<a name="225635460"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Vector-Optimized%20Library%20of%20Kernels/near/225635460" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kris <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Vector-Optimized.20Library.20of.20Kernels.html#225635460">(Feb 09 2021 at 01:41)</a>:</h4>
<p>Is runtime detection of CPU features a thing that I can implement in my own code? Or is that generally not a good idea? Do you intend on addressing it eventually?</p>



<a name="225635535"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Vector-Optimized%20Library%20of%20Kernels/near/225635535" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Edmund Cape <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Vector-Optimized.20Library.20of.20Kernels.html#225635535">(Feb 09 2021 at 01:42)</a>:</h4>
<p>(deleted)</p>



<a name="225635646"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Vector-Optimized%20Library%20of%20Kernels/near/225635646" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Vector-Optimized.20Library.20of.20Kernels.html#225635646">(Feb 09 2021 at 01:44)</a>:</h4>
<p><span class="user-mention" data-user-id="388175">@Kris</span> Yes, also see <a href="https://doc.rust-lang.org/std/macro.is_x86_feature_detected.html">https://doc.rust-lang.org/std/macro.is_x86_feature_detected.html</a></p>



<a name="225636165"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Vector-Optimized%20Library%20of%20Kernels/near/225636165" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Vector-Optimized.20Library.20of.20Kernels.html#225636165">(Feb 09 2021 at 01:52)</a>:</h4>
<p>by "that isn't something <strong>we</strong> do" I really mean "that's addressed elsewhere in std".  also see <a href="https://crates.io/crates/multiversion">https://crates.io/crates/multiversion</a></p>



<a name="225636292"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Vector-Optimized%20Library%20of%20Kernels/near/225636292" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kris <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Vector-Optimized.20Library.20of.20Kernels.html#225636292">(Feb 09 2021 at 01:54)</a>:</h4>
<p>Dag, you nailed that one. You just answered the question I just was trying to figure out how to ask!</p>



<a name="225636541"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Vector-Optimized%20Library%20of%20Kernels/near/225636541" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Vector-Optimized.20Library.20of.20Kernels.html#225636541">(Feb 09 2021 at 01:58)</a>:</h4>
<p><span class="user-mention" data-user-id="246783">@Miguel Raz Guzmán Macedo</span> That, or a solution about 7% stronger perhaps.</p>



<a name="225636557"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Vector-Optimized%20Library%20of%20Kernels/near/225636557" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kris <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Vector-Optimized.20Library.20of.20Kernels.html#225636557">(Feb 09 2021 at 01:59)</a>:</h4>
<p>So here's something that's got me stumped.  It's more of a Rust language question in general, but I just can't figure out the syntax in my little example.  In C++, I can just move a pointer along a large array and perform the SIMD operation on chunk after chunk. But in Rust I don't seem to have a strong enough grasp on raw pointers, borrowing, and moving and how I can accomplish the same thing.  Basically I want to walk the array performing some SIMD operations every 64, 128, 256 bytes (whatever the architecture supports that is largest).  Any examples anywhere that someone does that?</p>



<a name="225636727"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Vector-Optimized%20Library%20of%20Kernels/near/225636727" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Vector-Optimized.20Library.20of.20Kernels.html#225636727">(Feb 09 2021 at 02:01)</a>:</h4>
<p><span class="user-mention" data-user-id="388175">@Kris</span> Generally, Rust prefers you to <strong>not</strong> touch a raw pointer, and instead to index into an array or std::vec::Vec instead. You may have some math you wish to do using <code>std::mem::size_of</code> related to that, however.</p>



<a name="225636816"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Vector-Optimized%20Library%20of%20Kernels/near/225636816" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Vector-Optimized.20Library.20of.20Kernels.html#225636816">(Feb 09 2021 at 02:02)</a>:</h4>
<p>or even <a href="https://doc.rust-lang.org/std/primitive.slice.html#method.chunks">https://doc.rust-lang.org/std/primitive.slice.html#method.chunks</a> or <a href="https://doc.rust-lang.org/std/primitive.slice.html#method.array_chunks">https://doc.rust-lang.org/std/primitive.slice.html#method.array_chunks</a></p>



<a name="225637001"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Vector-Optimized%20Library%20of%20Kernels/near/225637001" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Vector-Optimized.20Library.20of.20Kernels.html#225637001">(Feb 09 2021 at 02:05)</a>:</h4>
<p>Basically, as an ethos, Rust would like to see you not have to care about how many bytes something is made of as much as possible, but if you do have to care, we would still like it if you interacted logically with the data instead of interacting with the raw bytes.</p>



<a name="225637113"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Vector-Optimized%20Library%20of%20Kernels/near/225637113" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Vector-Optimized.20Library.20of.20Kernels.html#225637113">(Feb 09 2021 at 02:07)</a>:</h4>
<p>If you really, really have to do raw pointer arithmetic I can point you to the API for doing so but like...!</p>



<a name="225637210"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Vector-Optimized%20Library%20of%20Kernels/near/225637210" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kris <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Vector-Optimized.20Library.20of.20Kernels.html#225637210">(Feb 09 2021 at 02:08)</a>:</h4>
<p>Thank you so much! Those look like just what I need. I prefer to do it the safe way as much as possible. That's the whole reason for migrating to Rust -- too many memory issues always creeping up.</p>



<a name="225644031"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Vector-Optimized%20Library%20of%20Kernels/near/225644031" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Vector-Optimized.20Library.20of.20Kernels.html#225644031">(Feb 09 2021 at 04:09)</a>:</h4>
<p>Hello there. For iterating over a long series of data you'd generally want to use something like a <a href="https://doc.rust-lang.org/std/primitive.slice.html#method.chunks_exact">chunks_exact</a>, and then for each chunk you could try casting the slice reference into a simd reference type. For this you might try <a href="https://docs.rs/bytemuck">bytemuck</a>. Once you've got a reference of the right type, you can try doing it with <a href="https://docs.rs/wide">wide</a>. Since I'm the lead of both bytemuck and also wide, if there's some way that you want them to interact and they don't do it right just give me a ping. I admit that between the two, and with the wide range of what you can so with slices in general, it can all  become quite daunting.</p>



<a name="225644200"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/Vector-Optimized%20Library%20of%20Kernels/near/225644200" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/Vector-Optimized.20Library.20of.20Kernels.html#225644200">(Feb 09 2021 at 04:13)</a>:</h4>
<p>oh, actually, now that i think about it you'd be better served just casting the entire slice to being a slice of the simd type just once at the start, then you do less work per loop iteration</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>